//场外势力Panel，场外势力包括空军，空降兵，导弹等

courtPanel = {
	showing : false,
	_location : [],
	node : null,

	tileWidth : null,
	tileHeight : null,
	tileCount : 7,
	
	LayerToNodeCoord : function(coord){
		return {x : coord.x - this.node.x, y : coord.y - this.node.y};
	},

	NodeToLayerCoord : function(coord){
		return {x : coord.x + this.node.x, y : coord.y + this.node.y};
	},

	CoordInBox : function(coord){
		return coord.x <= 0.5 * this.tileWidth
		&& coord.x >= -0.5 * this.tileWidth
		&& coord.y <= 0.5 * this.tileHeight
		&& coord.y >= -(this.tileCount - 0.5) * this.tileHeight;
	},
	
	CoordToIndex : function(coord){
		var index_tmp = Math.round(-coord.y / this.tileHeight);
		while (index_tmp >= 0){
			index_tmp -= tileEngine.xSize;
		}
		return index_tmp;
	},
	
	IndexToCoord : function(index){
		var index_tmp = index;
		while (index_tmp < 0){
			index_tmp += tileEngine.xSize;
		}
		return {x : 0, y : -index_tmp * this.tileHeight};
	},
	
	Initialize : function(){
		var winSize = cc.director.getWinSize();
		var standardTile = new cc.Sprite(resource.courtTileCenter_png);
		
		this.showing = false;
		this.tileWidth = standardTile.width;
		this.tileHeight = standardTile.height;

		this._location = [];
		for (var showStatus = 0; showStatus < 2; showStatus++){
			this._location[showStatus] = {
					x : winSize.width + 0.5 * this.tileWidth - showStatus * this.tileWidth,
					y : winSize.height - 1.0 * this.tileHeight
			};
		}

		this.node = new cc.Node();
		this.node.attr({x : this._location[0].x, y : this._location[0].y});
		campaignScene.battlelayer.addChild(this.node, 10);

		for (var idx = 0; idx < this.tileCount; idx++){
			var sprite = null;
			if (idx == 0){
				sprite = new cc.Sprite(resource.courtTileUp_png);
			}else if (idx == this.tileCount - 1){
				sprite = new cc.Sprite(resource.courtTileDown_png);
			}else{
				sprite = new cc.Sprite(resource.courtTileCenter_png);
			}
			sprite.attr( this.IndexToCoord(idx) );
			this.node.addChild(sprite, 0);
		}

		this.ShowUI();
	},
	
	ShowUI : function(){
		if (this.showing)
			return;
		this.showing = true;
		this.node.runAction(cc.moveTo(0.15, this._location[1].x, this._location[1].y));
	},
	
	HideUI : function(){
		if (this.showing == false)
			return;
		this.showing = false;
		this.node.runAction(cc.moveTo(0.15, this._location[0].x, this._location[0].y));
	}
};